package logic

import (
	"context"
	"sport/sportrpc/sportrpc"

	"sport/api/internal/svc"
	"sport/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentLogic {
	return &CommentLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CommentLogic) Comment(req *types.CommentRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	password, err := l.svcCtx.Sportrpc.Comment(l.ctx, &sportrpc.CommentRequest{
		UserId:  req.UserId,
		PostId:  req.PostId,
		Content: req.Content,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "评论成功",
		Data:    password,
		Code:    200,
	}, nil
}
